﻿using System;

public class Fraction : IFormattable
{
    private decimal numerator;
    private decimal denumerator;

    public Fraction(decimal numerator, decimal denumerator)
    {
        this.numerator = numerator;
        this.denumerator = denumerator;
    }

    public string ToString(string format, IFormatProvider formatProvider)
    {
        if (format==null)
        {
            return ToString();
        }
        if (format == "N")
        {
            return string.Format("{0}/{1}", numerator, denumerator);
        }
        if (format == "R")
        {
            return string.Format("{0:F2}", numerator / denumerator);
        }
        throw new FormatException("Unknown formatter");
    }

    public override string ToString()
    {
        return (numerator / denumerator).ToString();
    }
}

